package com.itheima.demo1;

import java.util.Scanner;

public class ArrayTest4 {
    public static void main(String[] args) {
        int[] arr=new int[2];
        Scanner sc = new Scanner(System.in);


        int max=arr[0];

        for (int i=0; i <arr.length;i++) {
            System.out.println("输入2个数字");
            arr[i] = sc.nextInt();

            if (arr[i] > max) {
                max=arr[i];
            }

        }
        //初始化最小值.在上面初始化后出错;因为上面for循环已经遍历了一次数组.下面继续用初始化的值会出错.
        int min=arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] < min) {
                min=arr[i];
            }
        }
        System.out.println("最大值是"+max);
        System.out.println("最小值是"+min);
    }
}
